<?php
	require_once '../libs/app.config.php';
	require_once INCLUDE_PATH.'template.config.php';
	require_once 'head.php';
	$charset?null:$charset='cn';
	$charset  = $tpm->escape($charset);

	$sql = sprintf('select a.id,a.title,a.content,ac.cat_name,ac.cat_name_en from articles a, article_cat ac where ac.cat_name="LATEST NEWS AND INFORMATION" ' .
			'and a.type="%s" and a.cat_id=ac.id order by add_time desc',$charset);
	$query = $tpm->query($sql);
	$totals = $tpm->num_rows($query);
	$tpn = new Page();


	if($id){
		$sql2 = sprintf('select a.title,a.content from articles a where a.id=%d and a.type="%s"',$id,$charset);
		$query = $tpm->query($sql2);
		if($tpm->affected_rows($query)){
			$latest = $tpm->fetch_array($query);
			$tpl->assign("latest",$latest);
		}
	}

//print_r($latest);

	if($charset=='en'){
		$tpn->pageft($totals,10);
		$sql = $sql." limit ".$tpn->getfirstcount().",10";
		$query = $tpm->query($sql);
		while($row = $tpm->fetch_array($query)) $list[]=$row;
		$tpl->assign("list",$list);
		$tpl->assign("page_nav",$tpn->getpagenav());
		$tpl->display("latest_en.html");
	}else{
		$tpn->pageft_cn($totals,10);
		$sql = $sql." limit ".$tpn->getfirstcount().",10";
		$query = $tpm->query($sql);
		while($row = $tpm->fetch_array($query)) $list[]=$row;
		$tpl->assign("list",$list);
		$tpl->assign("page_nav",$tpn->getpagenav());
		$tpl->display("latest_cn.html");
	}
?>